# Makefile for Echo Server using muduo library

# 编译器设置
CXX = g++
CXXFLAGS = -std=c++11 -g -Wall -O2

# 目录设置
INCLUDE_DIR = ./include
LIB_DIR = ./lib
SRC_DIR = ./src
BUILD_DIR = ./build

# muduo 库
MUDUO_LIBS = -lmuduo_net -lmuduo_base

# 系统库
SYS_LIBS = -lpthread

# 所有库
LIBS = -L$(LIB_DIR) $(MUDUO_LIBS) $(SYS_LIBS)

# 包含路径
INCLUDES = -I$(INCLUDE_DIR)

# 目标文件
TARGET = echo_server

# 源文件
SOURCES = $(SRC_DIR)/echo_server.cpp

.PHONY: all clean run

all: $(BUILD_DIR) $(TARGET)

$(BUILD_DIR):
	mkdir -p $(BUILD_DIR)

$(TARGET): $(SOURCES)
	$(CXX) $(CXXFLAGS) $(INCLUDES) -o $(BUILD_DIR)/$(TARGET) $(SOURCES) $(LIBS)
	@echo "✓ 编译成功！可执行文件: $(BUILD_DIR)/$(TARGET)"

clean:
	rm -rf $(BUILD_DIR)
	@echo "✓ 清理完成"

run: all
	@echo "启动 Echo 服务器（端口 8080）..."
	@$(BUILD_DIR)/$(TARGET)

help:
	@echo "可用命令："
	@echo "  make        - 编译 echo 服务器"
	@echo "  make clean  - 清理编译产物"
	@echo "  make run    - 编译并运行"
	@echo "  make help   - 显示帮助"

